import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import React, { useImperativeHandle, useRef, useState } from "react";
import Popup from "devextreme-react/popup";
import Form, { SimpleItem } from "devextreme-react/form";
export const PhaseLnputDialog = React.forwardRef((props, ref) => {
    const diaParams = useRef();
    const [twoVisible, setTwoVisible] = useState(false);
    const oKDataForm = useRef();
    const [formAllData, setFormAllData] = useState({
        OKData: "",
    });
    useImperativeHandle(ref, () => ({
        show: async (params) => {
            diaParams.current = params;
            setTwoVisible(true);
            setFormAllData({
                OKData: "",
            });
        },
        close: () => {
            setTwoVisible(false);
        },
    }));
    const validationRules = {
        OKData: [
            { type: "required", message: "请输入OK后才能完成操作！" },
            {
                type: "async",
                message: "请输入OK后才能完成操作！",
                validationCallback: async (item) => {
                    const result = item.value === "OK";
                    if (result) {
                        return true;
                    }
                    return false;
                },
            },
        ],
    };
    return (_jsx(Popup, { ...props, width: 400, height: 300, 
        // dragOutsideBoundary={true}
        resizeEnabled: true, visible: twoVisible, title: "确定提醒", onHiding: () => {
            setTwoVisible(false);
        }, toolbarItems: [
            {
                widget: "dxButton",
                toolbar: "bottom",
                location: "after",
                options: {
                    text: "取消",
                    onClick: () => {
                        setTwoVisible(false);
                    },
                },
            },
            {
                widget: "dxButton",
                toolbar: "bottom",
                location: "after",
                options: {
                    text: "确定",
                    type: "default",
                    validationGroup: "formAllDataData",
                    onClick: async () => {
                        if (oKDataForm.current) {
                            const devForm = oKDataForm.current;
                            const result = await devForm.instance.validate()
                                .complete;
                            if (result && result.isValid && result.status === "valid") {
                                setTwoVisible(false);
                                if (diaParams.current?.okCallback) {
                                    diaParams.current?.okCallback(true);
                                }
                            }
                        }
                    },
                },
            },
        ], contentRender: () => (_jsxs(_Fragment, { children: [_jsxs("div", { children: [_jsxs("p", { children: ["\u786E\u5B9A\u8981\u6267\u884C (", _jsx("span", { style: { color: "red" }, children: diaParams.current?.args?.title }), ")\u5417\uFF1F"] }), _jsx("p", { children: _jsx("span", { style: { color: "red", fontSize: "16px" }, children: diaParams.current?.args?.content ||
                                    "警告！此行为同步后会覆盖项目当前成果" }) }), _jsx("p", { children: "\u786E\u5B9A\u8981\u6267\u884C,\u8BF7\u60A8\u8F93\u5165OK" })] }), _jsx(Form, { ref: oKDataForm, formData: formAllData, labelLocation: "left", labelMode: "outside", focusStateEnabled: true, readOnly: false, showColonAfterLabel: true, alignItemLabels: true, children: _jsx(SimpleItem, { dataField: "OKData", label: { text: "输入OK" }, validationRules: validationRules.OKData }) })] })) }));
});
export default PhaseLnputDialog;
